<?php

namespace App\Jobs;

use GatewayWorker\Lib\Gateway;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class GatewayJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $client_id = '';
    protected $msg = '';

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($client_id, $msg)
    {
        $this->client_id = $client_id;
        $this->msg = $msg;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if(_empty_($this->client_id)){
            return;
        }

        if($this->client_id == 'all'){
            Gateway::sendToAll($this->msg);
        }else{
            Gateway::sendToClient($this->client_id, $this->msg);
        }
    }
}
